package com.itranlin.voddemo.utils;

import java.util.Collection;
import java.util.Map;

/**
 * Created by yangpeng on 2017/10/23.
 */
public class ValidUtil {

    /**
     * 进行空参校验,可以检验 null 空字符串,undefined字符串,空集合,空map
     *
     * @param args 可以传多个参数进行空参检验
     * @return
     */
    public static boolean isEmpty(Object... args) {
        Boolean result = false;
        for (Object o : args) {
            //如果是null,返回true
            if (o == null) {
                result = true;
            } else {
                //如果是集合类
                if (o instanceof Collection) {
                    Collection c = (Collection) o;
                    //集合大小为0  返回true
                    if (c.size() == 0) {
                        result = true;
                    }

                } else {
                    //如果是Map集合
                    if (o instanceof Map) {
                        Map m = (Map) o;
                        if (m.size() == 0) {
                            result = true;

                        }
                    } else {
                        //其他对象
                        if ("".equals(o.toString()) || "null".equals(o.toString()) || "undefined".equals(o.toString())) {
                            result = true;

                        }
                    }
                }
            }
        }
        return result;
    }

    public static boolean notEmpty(Object... args) {
        return !isEmpty(args);
    }

}
